#!/bin/bash

# malloc size
# expect size
malloc1_test() {
    size=$1
    ret=`./malloc1 $1`
    if [[ x"$ret" == x""  ]];then
        ret="NULL"
    fi
    #echo "in: $1, malloc: $ret, expect $2"
    printf "in: %4s, malloc: %4s, expect %4s, ret %s\n" $1 $ret $2 $?
}


make clean
make malloc1
make malloc2_test

echo -e "\n= malloc1 test start"
malloc1_test -1   0
malloc1_test 0    0
malloc1_test 10   4096
malloc1_test 1024 4096
malloc1_test 4095 4096
malloc1_test 4096 4096
malloc1_test 4196 4096

echo -e "\n= malloc2 test start"
./malloc2_test
if [ $? == 0 ]; then
    echo "Pass"
else
    echo "Faild"
    exit 1
fi

gdb ./malloc2_test -ex "source.gdb" -ex r
